package com.kummuna.ui;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.TimeZone;

import com.kummuna.R;
import com.kummuna.R.layout;
import com.kummuna.R.menu;

import android.location.Address;
import android.location.Geocoder;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;



public class AndroidGPSTrackingActivity extends Activity implements LocationListener {
	Button btnShowLocation;
    //List<Address> mAddresses;
    TextView mCurrentSpeed;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_android_gpstracking);
		btnShowLocation = (Button) findViewById(R.id.btnShowLocation);
		//mAddresses = new ArrayList<Address>();
		mCurrentSpeed = (TextView) findViewById(R.id.txtLocation);
		LocationManager mlocManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
		mlocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, (android.location.LocationListener) this);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.android_gpstracking, menu);
		return true;
	}

	@Override
	public void onLocationChanged(Location loc) {
		loc.getLatitude();
	    loc.getLongitude();

	    /*Geocoder gcd = new Geocoder(getApplicationContext(), Locale.getDefault());
	    try {
	        mAddresses = gcd.getFromLocation(loc.getLatitude(),loc.getLongitude(), 1);

	    } catch (IOException e) {

	    }*/
	    //String cityName = (mAddresses != null) ? mAddresses.get(0).getLocality() : TimeZone.getDefault().getID();
	    //String countryName = (mAddresses != null) ? mAddresses.get(0).getCountryName() : Locale.getDefault().getDisplayCountry().toString();
	    mCurrentSpeed.setText("Longitude"+loc.getLongitude()+", Latitude"+loc.getLatitude());
	}

	@Override
	public void onProviderDisabled(String arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onProviderEnabled(String arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onStatusChanged(String arg0, int arg1, Bundle arg2) {
		// TODO Auto-generated method stub
		
	}
}
